/* main.c */
#include "app_inc.h"


FATFS    FatFs;				/* File system object for each logical drive */
FIL      File[2];				/* File objects */
DIR      Dir;					/* Directory object */
FRESULT  gFatFsResultFlags;
FIL      gFatFsFile;
char     gFatFsLine[100];

int main(void)
{
    BSP_InitSystem();
    BSP_InitStdioLPUART(115200UL);
    
    printf("\r\n\r\nFatFS Example\r\n");
    printf("Compiled at %s on %s\r\n", __TIME__, __DATE__);
    
    /* 挂载磁盘 */
    gFatFsResultFlags = f_mount(&FatFs, "", 1); /* 立刻挂载 */
    printf("gFatFsResultFlags: %d\r\n", gFatFsResultFlags);
    
    /* 创建一个文件 */
    
    gFatFsResultFlags = f_open(&gFatFsFile, "/hello.txt", FA_OPEN_ALWAYS | FA_WRITE);
    printf("gFatFsResultFlags: %d\r\n", gFatFsResultFlags);
    if (gFatFsResultFlags == FR_OK)
    {
        f_printf(&gFatFsFile, "[f_printf] Hello, FatFs.\r\n");
        f_puts("[f_puts] Hello, FatFs.\r\n", &gFatFsFile);
        f_close(&gFatFsFile);
    }
    
    gFatFsResultFlags = f_open(&gFatFsFile, "/main.py", FA_READ);
    printf("gFatFsResultFlags: %d\r\n", gFatFsResultFlags);
    /* Read all lines and display it */
    while (f_gets(gFatFsLine, sizeof gFatFsLine, &gFatFsFile))
    {
        printf(gFatFsLine);
    }
    f_close(&gFatFsFile);
    
    
    gFatFsResultFlags = f_open(&gFatFsFile, "/hello.txt", FA_READ);
    printf("gFatFsResultFlags: %d\r\n", gFatFsResultFlags);
    /* Read all lines and display it */
    while (f_gets(gFatFsLine, sizeof gFatFsLine, &gFatFsFile))
    {
        printf(gFatFsLine);
    }
    f_close(&gFatFsFile);
    
    
    printf("ALL TEST DONE.\r\n");
    
    while (1)
    {
        
    }
}


/* EOF. */
